/**
 * 
 */
package kr.co.insoft.core.repository.orchestration.impl;

import java.util.List;

import kr.co.insoft.core.mapper.orchestration.OrchestrationTreeMapper;
import kr.co.insoft.core.model.orchestration.OrchestrationTreeMetadataEntityModel;
import kr.co.insoft.core.model.orchestration.OrchestrationTreeParamModel;
import kr.co.insoft.core.repository.orchestration.OrchestrationTreeRepository;
import kr.co.insoft.framework.exceptions.ExceptionCode;
import kr.co.insoft.framework.exceptions.RepositoryException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

/**
 * @author IN-SOFT Inc. GoodwillDD(sylee@in-soft.co.kr)
 * 
 */
@Repository
public class OrchestrationTreeRepositoryImpl implements
		OrchestrationTreeRepository {

	private static final Logger OrchestrationTreeRepositoryImplLog = LoggerFactory
			.getLogger(OrchestrationTreeRepositoryImpl.class);

	@Autowired
	OrchestrationTreeMapper orchestrationTreeMapper;

	public List<OrchestrationTreeMetadataEntityModel> getTree(
			OrchestrationTreeParamModel orchestrationTreeParamModel)
			throws RepositoryException {
		try {
			Assert.notNull(orchestrationTreeParamModel);
		} catch (IllegalArgumentException e) {
			OrchestrationTreeRepositoryImplLog.error(
					ExceptionCode.ASSERT_FORMAT, orchestrationTreeParamModel);
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}
		try {
			return orchestrationTreeMapper.getTree(orchestrationTreeParamModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	@Override
	public List<OrchestrationTreeMetadataEntityModel> getEventChainTreeNonRoot(
			OrchestrationTreeParamModel orchestrationTreeParamModel)
			throws RepositoryException {
		try {
			Assert.notNull(orchestrationTreeParamModel);
		} catch (IllegalArgumentException e) {
			OrchestrationTreeRepositoryImplLog.error(
					ExceptionCode.ASSERT_FORMAT, orchestrationTreeParamModel);
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}
		try {
			return orchestrationTreeMapper
					.getEventChainTreeNonRoot(orchestrationTreeParamModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}
}
